#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>

#define MAXLINE 4096
#define PORT 6666
int main (int argc,char **argv)
{
	int sockfd,n;
	char recvlinep[MAXLINE+1],sendline[MAXLINE+1];
	struct sockaddr_in servaddr;

	if (argc != 2 ){
		printf("usage: ./client <ipaddress>\n");
		exit(0);
	}

	if ((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0){
		printf("create socket error: %s(errno: %d)\n", strerror(errno),errno);
		exit(0);
	}

	memset(&servaddr,0,sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(PORT);
	servaddr.sin_addr.s_addr = inet_addr(argv[1]);
	if (connect (sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr)) <0){
		printf("connect socket error: %s(errno: %d)\n", strerror(errno),errno);
		exit(0);
	}
	printf("send msg to server : \n");
	fgets(sendline,MAXLINE,stdin);
	if (send(sockfd,sendline,strlen(sendline),0) < 0){
		printf("send socket error: %s(errno: %d)\n", strerror(errno),errno);
		exit(0);
	}

	close(sockfd);
	exit(0);



}
